<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="100px">
            <el-form-item label="活动标题:" prop="title" >
                <el-input
                    v-model="queryParams.title"
                    placeholder="请输入活动标题"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="村社:" prop="communityId">
                <el-select v-model="queryParams.communityId" placeholder="请选择对应的村社或村" clearable>
                    <el-option
                        v-for="community in communityList"
                        :key="community.communityId"
                        :label="community.communityName"
                        :value="community.communityId"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="审核状态" prop="audit">
                <el-select v-model="queryParams.audit" placeholder="审核状态" clearable>
                    <el-option
                        v-for="dict in dict.type.sys_user_act_status"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5" style="display: none">
                <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                    v-hasPermi="['docs:peopleActivity:add']"
                >新增
                </el-button>
            </el-col>
            <el-col :span="1.5" style="display: none">
                <el-button
                    type="success"
                    plain
                    icon="el-icon-edit"
                    size="mini"
                    :disabled="single"
                    @click="handleUpdate"
                    v-hasPermi="['docs:peopleActivity:edit']"
                >修改
                </el-button>
            </el-col>
            <el-col :span="1.5" style="display: none">
                <el-button
                    type="danger"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    :disabled="multiple"
                    @click="handleDelete"
                    v-hasPermi="['docs:peopleActivity:remove']"
                >删除
                </el-button>
            </el-col>
            <el-col :span="1.5" style="display: none">
                <el-button
                    type="warning"
                    plain
                    icon="el-icon-download"
                    size="mini"
                    @click="handleExport"
                    v-hasPermi="['docs:peopleActivity:export']"
                >导出
                </el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="peopleActivityList" @selection-change="handleSelectionChange" border>

            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="栏目" align="center" prop="columnName"/>
            <el-table-column label="村社" align="center" prop="communityName"/>
            <el-table-column label="活动标题" align="center" prop="title" min-width="200" :show-overflow-tooltip="true"/>
            <el-table-column label="类型" align="center" prop="type">
                <template slot-scope="scope">
                    <el-tag type="dange" v-if="scope.row.type==0">线上</el-tag>
                    <el-tag type="success" v-if="scope.row.type==1">线下</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="奖励积分" align="center" prop="score">
                <template slot-scope="scope"><el-tag type="danger">+{{scope.row.score}}</el-tag></template>
            </el-table-column>
            <el-table-column label="参与人" align="center" prop="peopleName"/>

            <el-table-column label="申请时间" align="center" prop="applyTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d} {h}:{i}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="审核状态" align="center" prop="audit">
                <template slot-scope="scope">
                    <el-tag type="dange" v-if="scope.row.audit===0">待审核</el-tag>
                    <el-tag type="success" v-if="scope.row.audit===1">已审核</el-tag>
                    <el-tag type="success" v-if="scope.row.audit===2">待签到</el-tag>
                    <el-tag type="success" v-if="scope.row.audit===3">已签到</el-tag>
                    <el-tag type="success" v-if="scope.row.audit===4">审核不通过</el-tag>
                    <el-tag type="success" v-if="scope.row.audit===5">取消签到</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="审核人" align="center" prop="auditPeopleName"/>
            <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.auditTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-view"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['docs:peopleActivity:edit']"
                    >查看
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />
        <!-- 添加或修改居民评议对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
            <el-descriptions  border column="1" size="medium">
                <el-descriptions-item label="审核状态" label-class-name="my-label">
                    <el-tag type="dange" v-if="form.audit===0">待审核</el-tag>
                    <el-tag type="success" v-if="form.audit===1">已审核</el-tag>
                    <el-tag type="success" v-if="form.audit===2">待签到</el-tag>
                    <el-tag type="success" v-if="form.audit===3">已签到</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="审核人">{{form.auditPeopleName}}</el-descriptions-item>
                <el-descriptions-item label="审核时间">{{ parseTime(form.auditTime,'{y}-{m}-{d} {h}:{i}') }}</el-descriptions-item>
                <el-descriptions-item label="活动类型">
                    <el-tag type="dange" v-if="form.type==0">线上</el-tag>
                    <el-tag type="success" v-if="form.type==1">线下</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="活动标题">{{form.title}}</el-descriptions-item>
                <el-descriptions-item label="所属村社">{{form.communityName}}</el-descriptions-item>
                <el-descriptions-item label="所属栏目">{{form.columnName}}</el-descriptions-item>
                <el-descriptions-item label="参与人">{{form.peopleName}}</el-descriptions-item>
                <el-descriptions-item label="参与时间">{{ parseTime(form.applyTime) }}</el-descriptions-item>
                <el-descriptions-item label="奖励积分"><el-tag type="danger">+{{form.score}}</el-tag></el-descriptions-item>
                <el-descriptions-item label="参与内容">{{form.suggest}}</el-descriptions-item>
                <el-descriptions-item label="参与凭证" v-if="form.type==0">
                    <el-image :src="form.imgs" style="width: 200px;"></el-image>
                </el-descriptions-item>
            </el-descriptions>
        </el-dialog>
        <!-- 添加或修改活动参与对话框 -->
<!--        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>-->
<!--            <el-form ref="form" :model="form" :rules="rules" label-width="80px">-->
<!--                <el-form-item label="活动标题" prop="title">-->
<!--                    <el-input v-model="form.title" placeholder="请输入活动标题"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="参与人姓名" prop="peopleName">-->
<!--                    <el-input v-model="form.peopleName" placeholder="请输入参与人姓名"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="参与人Id" prop="peopleId">-->
<!--                    <el-input v-model="form.peopleId" placeholder="请输入参与人Id"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="审核人名称" prop="auditPeopleName">-->
<!--                    <el-input v-model="form.auditPeopleName" placeholder="请输入审核人名称"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="审核人ID" prop="auditPeople">-->
<!--                    <el-input v-model="form.auditPeople" placeholder="请输入审核人ID"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="所属类目" prop="columnId">-->
<!--                    <el-input v-model="form.columnId" placeholder="请输入所属类目"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="栏目" prop="columnName">-->
<!--                    <el-input v-model="form.columnName" placeholder="请输入栏目"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="村社" prop="communityId">-->
<!--                    <el-input v-model="form.communityId" placeholder="请输入村社"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="村社名" prop="communityName">-->
<!--                    <el-input v-model="form.communityName" placeholder="请输入村社名"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="活动内容" prop="content">-->
<!--                    <el-input v-model="form.content" type="textarea" placeholder="请输入内容"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="参会的活动图片" prop="imgs">-->
<!--                    <image-upload v-model="form.imgs"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="活动图片" prop="imgUrl">-->
<!--                    <el-input v-model="form.imgUrl" placeholder="请输入活动图片"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="参与人数" prop="partake">-->
<!--                    <el-input v-model="form.partake" placeholder="请输入参与人数"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="参与活动活动积分" prop="score">-->
<!--                    <el-input v-model="form.score" placeholder="请输入参与活动活动积分"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="审核状态 0:待审核，1：已审核" prop="audit">-->
<!--                    <el-input v-model="form.audit" placeholder="请输入审核状态 0:待审核，1：已审核"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="活动地址" prop="address">-->
<!--                    <el-input v-model="form.address" placeholder="请输入活动地址"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="审核时间" prop="auditTime">-->
<!--                    <el-date-picker clearable-->
<!--                                    v-model="form.auditTime"-->
<!--                                    type="date"-->
<!--                                    value-format="yyyy-MM-dd"-->
<!--                                    placeholder="请选择审核时间">-->
<!--                    </el-date-picker>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="申请时间" prop="applyTime">-->
<!--                    <el-date-picker clearable-->
<!--                                    v-model="form.applyTime"-->
<!--                                    type="date"-->
<!--                                    value-format="yyyy-MM-dd"-->
<!--                                    placeholder="请选择申请时间">-->
<!--                    </el-date-picker>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="有效期:开始" prop="expireStart">-->
<!--                    <el-date-picker clearable-->
<!--                                    v-model="form.expireStart"-->
<!--                                    type="date"-->
<!--                                    value-format="yyyy-MM-dd"-->
<!--                                    placeholder="请选择有效期:开始">-->
<!--                    </el-date-picker>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="有效期结束" prop="expireEnd">-->
<!--                    <el-date-picker clearable-->
<!--                                    v-model="form.expireEnd"-->
<!--                                    type="date"-->
<!--                                    value-format="yyyy-MM-dd"-->
<!--                                    placeholder="请选择有效期结束">-->
<!--                    </el-date-picker>-->
<!--                </el-form-item>-->
<!--            </el-form>-->
<!--            <div slot="footer" class="dialog-footer">-->
<!--                <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--                <el-button @click="cancel">取 消</el-button>-->
<!--            </div>-->
<!--        </el-dialog>-->
    </div>
</template>

<script>
import {
    listPeopleActivity,
    getPeopleActivity,
    delPeopleActivity,
    addPeopleActivity,
    updatePeopleActivity
} from "@/api/docs/peopleActivity";
import {listCommunity} from "@/api/organization/community";

export default {
    name: "PeopleActivity",
    dicts:['sys_user_act_status'],
    data() {
        return {
            communityList: [],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 活动参与表格数据
            peopleActivityList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                title: null,
                peopleName: null,
                peopleId: null,
                auditPeopleName: null,
                auditPeople: null,
                columnId: null,
                columnName: null,
                communityId: null,
                communityName: null,
                content: null,
                imgs: null,
                imgUrl: null,
                partake: null,
                score: null,
                audit: null,
                status: null,
                address: null,
                type: null,
                auditTime: null,
                applyTime: null,
                expireStart: null,
                expireEnd: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                title: [
                    {required: true, message: "活动标题不能为空", trigger: "blur"}
                ],
                content: [
                    {required: true, message: "活动内容不能为空", trigger: "blur"}
                ],
                status: [
                    {required: true, message: "状态不能为空", trigger: "change"}
                ],
            }
        };
    },
    created() {
        this.getList();
        this.getCommunityList();
    },
    methods: {
        getCommunityList(){
            listCommunity(this.commonVars).then(response=>{
                this.communityList = response.rows
            })
        },
        /** 查询活动参与列表 */
        getList() {
            this.loading = true;
            listPeopleActivity(this.queryParams).then(response => {
                this.peopleActivityList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                peopleActivityId: null,
                title: null,
                peopleName: null,
                peopleId: null,
                auditPeopleName: null,
                auditPeople: null,
                columnId: null,
                columnName: null,
                communityId: null,
                communityName: null,
                content: null,
                imgs: null,
                imgUrl: null,
                partake: null,
                score: null,
                audit: null,
                status: null,
                address: null,
                type: null,
                auditTime: null,
                applyTime: null,
                expireStart: null,
                expireEnd: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.peopleActivityId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加活动参与";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const peopleActivityId = row.peopleActivityId || this.ids
            getPeopleActivity(peopleActivityId).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "查看";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.peopleActivityId != null) {
                        updatePeopleActivity(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addPeopleActivity(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const peopleActivityIds = row.peopleActivityId || this.ids;
            this.$modal.confirm('是否确认删除活动参与编号为"' + peopleActivityIds + '"的数据项？').then(function () {
                return delPeopleActivity(peopleActivityIds);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => {
            });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('docs/peopleActivity/export', {
                ...this.queryParams
            }, `peopleActivity_${new Date().getTime()}.xlsx`)
        }
    }
};
</script>
